package org.example.BIO_Turn;

import javax.naming.ldap.SortKey;
import java.io.*;
import java.net.Socket;
import java.util.UUID;

public class Task implements Runnable{

    private Socket socket;

    public Task(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            BufferedReader bf = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String msg;
            while ((msg = bf.readLine()) != null) {
                this.allHandle(msg);
            }
        } catch (IOException e) {
            Server.socketArrayList.remove(socket);
        }
    }

    private void allHandle(String msg) throws IOException {
        System.out.println("服务端接收到消息，即将进行群转");
        for (Socket socket1 : Server.socketArrayList) {
            // 群发
            PrintStream printStream = new PrintStream(socket1.getOutputStream());
            printStream.println(msg);
        }
    }
}
